package example.step2;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class ReferenceSerial {
    public static void main(String[] args) throws Exception {
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
                "E:\\idea-workspace\\gitee\\demo\\serializable\\src\\main\\java\\objfile\\ref.obj"));
        // 检测对象
        Integer first = new Integer("2");
        Integer second = Integer.valueOf("2");
        Boolean third = new Boolean("true");
        Integer four = new Integer("11");
        // 第一次序列化first
        out.writeObject(first);
        out.writeObject(new Integer("3"));
        // 第二次序列化first，这里开始使用引用的方式
        out.writeObject(first);
        out.writeObject(new Integer("4"));
        out.writeObject(new Integer("5"));
        // 第一次序列化second，对象方式
        out.writeObject(second);
        out.writeObject(new Integer("6"));
        out.writeObject(new Integer("7"));
        // 第二次序列化second，引用方式
        out.writeObject(second);
        // 第一次序列化third，对象方式
        out.writeObject(third);
        out.writeObject(new Integer("6"));
        // 引用方式， 使用引用方式其值就不会变化
        out.writeObject(second);
        out.writeObject(first);
        out.writeObject(third);

        out.writeObject(four)   ;
        out.writeObject(new Integer("22"));
        out.writeObject(four);


        out.close();
    }
}